CC      = arm-linux-gcc
LD      = arm-linux-ld
AR      = arm-linux-ar
OBJCOPY = arm-linux-objcopy
OBJDUMP = arm-linux-objdump

CONFIG_SYS_TEXT_BASE :=0X20000000
COPY_BL2_SIZE :=0x80000

INCLUDEDIR 	:= $(shell pwd)/include
CFLAGS 		:=-g -Wall -O2 -fno-builtin -nostdlib -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
		-DCOPY_BL2_SIZE=$(COPY_BL2_SIZE)
CPPFLAGS   	:=-g -nostdinc -nostdlib -I$(INCLUDEDIR) -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
		-DCOPY_BL2_SIZE=$(COPY_BL2_SIZE)
		
export 	CC AR LD OBJCOPY OBJDUMP INCLUDEDIR CFLAGS CPPFLAGS 

objs := start.o memory.o nand_cp.o mmc_cp.o main.o uart.o clock.o lib/libc.a


all: stdio.bin
	make -C ./BL1
	cat ./BL1/BL1.bin stdio.bin > 210.bin
	ls -al ./BL1/start.bin
	ls -al ./BL1/BL1.bin
	ls -al stdio.bin
	ls -al 210.bin
	
stdio.bin: $(objs)
	${LD} -Ttext ${CONFIG_SYS_TEXT_BASE} -Tstdio.lds -o stdio.elf $^
	${OBJCOPY} -O binary -S stdio.elf $@
	${OBJDUMP} -D stdio.elf > stdio.dis


.PHONY : lib/libc.a
lib/libc.a:
	cd lib; make; cd ..
	
%.o:%.c
	${CC} $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

%.o:%.S
	${CC} $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

clean:
	make  clean -C lib
	make clean -C ./BL1/
	rm -f *.bin *.elf *.dis *.o 
	
